home *** CD-ROM | disk | FTP | other *** search
- class SideScroller.Ground
- {
- var mcRef;
- var oParentObject;
- var nMinX;
- var nMaxX;
- var nMinY;
- var nMaxY;
- var aPoints;
- var nSearchProgression;
- static var aGrounds;
- static var aActiveWorkGrounds;
- static var oEnterFrameListener;
- static var bInited;
- static var ITERATION_X = 25;
- static var ITERATION_Y = 10;
- static var SEARCHS_PER_FRAME = 1;
- static var MAX_WORKING_GROUNDS = 3;
- function Ground(__mcRef, __oParentObject)
- {
- this.mcRef = __mcRef;
- this.oParentObject = __oParentObject;
- this.mcRef._visible = false;
- var _loc2_ = this.mcRef.getBounds(this.oParentObject.ParentLayer.Ref);
- this.nMinX = _loc2_.xMin;
- this.nMaxX = _loc2_.xMax;
- this.nMinY = _loc2_.yMin;
- this.nMaxY = _loc2_.yMax;
- this.aPoints = new Array();
- this.nSearchProgression = this.nMinX + (SideScroller.Ground.ITERATION_X - this.nMinX % SideScroller.Ground.ITERATION_X);
- SideScroller.Ground.doScheduleGround(this);
- }
- static function doStaticEnterFrame()
- {
- if(SideScroller.Ground.aGrounds.length > 0)
- {
- if(SideScroller.Ground.aActiveWorkGrounds.length < SideScroller.Ground.MAX_WORKING_GROUNDS)
- {
- SideScroller.Ground.doStartGroundWork();
- }
- }
- for(var _loc1_ in SideScroller.Ground.aActiveWorkGrounds)
- {
- SideScroller.Ground.aActiveWorkGrounds[_loc1_].doEnterFrame();
- }
- }
- static function doClean()
- {
- delete SideScroller.Ground.aGrounds;
- delete SideScroller.Ground.aActiveWorkGrounds;
- MovieClip.removeListener(SideScroller.Ground.oEnterFrameListener);
- delete SideScroller.Ground.oEnterFrameListener.onEnterFrame;
- delete SideScroller.Ground.oEnterFrameListener;
- SideScroller.Ground.bInited = false;
- }
- static function doInit()
- {
- mx.transitions.OnEnterFrameBeacon.init();
- SideScroller.Ground.oEnterFrameListener = new Object();
- SideScroller.Ground.oEnterFrameListener.onEnterFrame = Library.Utils.Delegate.create(SideScroller.Ground,SideScroller.Ground.doStaticEnterFrame);
- MovieClip.addListener(SideScroller.Ground.oEnterFrameListener);
- SideScroller.Ground.aGrounds = new Array();
- SideScroller.Ground.aActiveWorkGrounds = new Array();
- SideScroller.Ground.bInited = true;
- }
- static function doStartGroundWork()
- {
- var _loc4_ = undefined;
- var _loc1_ = Infinity;
- var _loc2_ = undefined;
- for(var _loc3_ in SideScroller.Ground.aGrounds)
- {
- if(SideScroller.Ground.aGrounds[_loc3_].StartPos < _loc1_)
- {
- _loc1_ = SideScroller.Ground.aGrounds[_loc3_].StartPos;
- _loc2_ = Number(_loc3_);
- }
- }
- _loc4_ = SideScroller.Ground.aGrounds[_loc2_];
- SideScroller.Ground.aGrounds.splice(_loc2_,1);
- SideScroller.Ground.aActiveWorkGrounds.push(_loc4_);
- }
- static function onGroundWorkComplete(__oGround)
- {
- for(var _loc2_ in SideScroller.Ground.aActiveWorkGrounds)
- {
- if(SideScroller.Ground.aActiveWorkGrounds[_loc2_] == __oGround)
- {
- SideScroller.Ground.aActiveWorkGrounds.splice(Number(_loc2_),1);
- }
- }
- }
- static function doScheduleGround(__oGround)
- {
- if(!SideScroller.Ground.bInited)
- {
- SideScroller.Ground.doInit();
- }
- SideScroller.Ground.aGrounds.push(__oGround);
- }
- function doEnterFrame()
- {
- var _loc7_ = 1;
- while(_loc7_ <= SideScroller.Ground.SEARCHS_PER_FRAME)
- {
- if(this.nSearchProgression <= this.nMaxX)
- {
- var _loc6_ = this.nMaxY;
- var _loc2_ = undefined;
- _loc2_ = this.nMaxY - 1;
- while(_loc2_ >= this.nMinY)
- {
- var _loc4_ = this.nSearchProgression + this.oParentObject.ParentLayer.Ref._x;
- var _loc3_ = _loc2_ + this.oParentObject.ParentLayer.Ref._y;
- var _loc5_ = this.mcRef.hitTest(_loc4_,_loc3_,true);
- if(_loc5_)
- {
- _loc6_ = _loc2_;
- }
- else
- {
- _loc2_ = -Infinity;
- }
- _loc2_ -= SideScroller.Ground.ITERATION_Y;
- }
- this.aPoints.push({nX:this.nSearchProgression,nY:_loc6_});
- this.nSearchProgression += SideScroller.Ground.ITERATION_X;
- }
- else
- {
- SideScroller.Ground.onGroundWorkComplete(this);
- }
- _loc7_ = _loc7_ + 1;
- }
- }
- function getGroundAt(__nPositionX)
- {
- var _loc3_ = __nPositionX - __nPositionX % SideScroller.Ground.ITERATION_X;
- var _loc6_ = _loc3_ + SideScroller.Ground.ITERATION_X;
- var _loc4_ = this.nMaxY;
- var _loc5_ = this.nMaxY;
- var _loc2_ = undefined;
- _loc2_ = 0;
- while(_loc2_ <= this.aPoints.length - 1)
- {
- if(this.aPoints[_loc2_].nX == _loc3_)
- {
- _loc4_ = this.aPoints[_loc2_].nY;
- }
- if(this.aPoints[_loc2_].nX == _loc6_)
- {
- _loc5_ = this.aPoints[_loc2_].nY;
- }
- _loc2_ = _loc2_ + 1;
- }
- var _loc8_ = (__nPositionX - _loc3_) / (_loc6_ - _loc3_);
- var _loc10_ = _loc5_ - _loc4_;
- var _loc9_ = _loc4_ + _loc10_ * _loc8_;
- return _loc9_;
- }
- function doDestroy()
- {
- this.oParentObject.ParentLayer.doRemoveListener(this);
- this.aPoints = new Array();
- delete this.aPoints;
- delete this.oParentObject;
- }
- function get StartPos()
- {
- return this.nMinX;
- }
- function get MinY()
- {
- return this.nMinY;
- }
- function get MaxY()
- {
- return this.nMaxY;
- }
- function get EndPos()
- {
- return this.nMaxX;
- }
- }
-